common-path 1.0.0

Finds the common prefix between a set of paths
Documentation

Calculates the common prefix for a set of paths, if a common prefix exists

Example

# extern crate common_path;
use std::path::{PathBuf, Path};
use common_path::common_path;

# fn main() {
let baz = Path::new("/foo/bar/baz");
let quux = Path::new("/foo/bar/quux");
let prefix = common_path(baz, quux).unwrap();
assert_eq!(prefix, Path::new("/foo/bar").to_path_buf());
# }

Or for more than 2 paths:

# extern crate common_path;
use std::path::{PathBuf, Path};
use common_path::common_path_all;

# fn main() {
let baz = Path::new("/foo/bar/baz");
let quux = Path::new("/foo/bar/quux");
let foo = Path::new("/foo/bar/foo");
let prefix = common_path_all(vec![baz, quux, foo]).unwrap();
assert_eq!(prefix, Path::new("/foo/bar").to_path_buf());
# }